package com.nami.logic.task;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.TimeInterval;
import com.nami.store.api.service.RemoteInvalidMsgService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.util.Date;

@Slf4j
@RequiredArgsConstructor
@Service
public class ClearMsgTask {

    @DubboReference
    RemoteInvalidMsgService messageService;


    /**
     * 暂时简单处理
     *
     */

    @Scheduled(cron = "0 0/3 * * * ?")
    public void clearInboxMsgTask() {
        try {
            TimeInterval timer = DateUtil.timer();
            log.info("[task] clearInboxMsgTask");
            messageService.delInBoxMsgByTime("test", DateUtil.offsetDay(new Date(), -1));
            log.info("[task] clearInboxMsgTask done. use time:{}ms", timer.interval());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("[task] clearInboxMsgTask error", e);
        }
    }

    @Scheduled(cron = "0 0/3 * * * ?")
    public void clearSendBoxMsgs() {
        try {
            TimeInterval timer = DateUtil.timer();
            log.info("[task] clearSendBoxMsgs");
            messageService.delSendBoxMsgByTime("test", DateUtil.offsetDay(new Date(), -1));
            log.info("[task] clearSendBoxMsgs done. use time:{}ms", timer.interval());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("[task] clearSendBoxMsgs error", e);
        }
    }

}
